
const getIPAdress = () => {
  let interfaces = require('os').networkInterfaces();
  for (var devName in interfaces) {
    var iface = interfaces[devName];
    for (var i = 0; i < iface.length; i++) {
      let alias = iface[i];
      if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) {
        // console.log(alias.address);

        return alias.address
      }
    }
  }
}

/**
 * length：需要的字符串长度
 * 返回值：随机字符串
 */
 const getUUID = length => {
  let str = 'abcdefghijklmnopqrstuvwxyz0123456789'
  let result = ''
  for (let i = 0; i < length; i++) {
    result += str[parseInt(Math.random() * str.length)]
  }
  return result
}

module.exports = {
  getIPAdress,
  getUUID
}